Skip to content

[17.0][ADD] survey_question_type_model_selection: new module#209

Open
eduezerouali-tecnativa wants to merge 1 commit intoOCA:17.0from
Tecnativa:17.0-add-survey_question_type_model_selection
Open

[17.0][ADD] survey_question_type_model_selection: new module#209
eduezerouali-tecnativa wants to merge 1 commit intoOCA:17.0from
Tecnativa:17.0-add-survey_question_type_model_selection

Conversation

@eduezerouali-tecnativa
Copy link
Copy Markdown

This module extends the Survey question types by introducing a new question type that allows selecting records from any model, with configurable domain filters. This makes it possible to display dynamic, filtered model-based selections directly within surveys.

@Tecnativa TT59700

ping @pilarvargas-tecnativa @carlos-lopez-tecnativa @pedrobaeza

@eduezerouali-tecnativa eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch from 6a9e1c1 to 433d4bc Compare December 16, 2025 12:24
@pedrobaeza pedrobaeza added this to the 17.0 milestone Dec 17, 2025
@eduezerouali-tecnativa eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 2 times, most recently from a197d13 to 366a795 Compare December 18, 2025 14:32
@pilarvargas-tecnativa
Copy link
Copy Markdown

It's perfect, except that even though the answers are correctly stored in the participation section, when you go to the review in the survey itself, you can't see them, only the questions.

image

For this, I want to remind you that you must add them to the view that is printed because, if I'm not mistaken, it checks the types to style them.

@eduezerouali-tecnativa eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 2 times, most recently from 5b5422e to 82e6168 Compare December 31, 2025 10:24
@eduezerouali-tecnativa
Copy link
Copy Markdown
Author

You are right. Now is displaying correctly. Thank you for your review.
Selección_046

@pedrobaeza
Copy link
Copy Markdown
Member

ping @pilarvargas-tecnativa

@eduezerouali-tecnativa eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 2 times, most recently from 613de04 to a60e05b Compare March 6, 2026 15:18
"survey_id": cls.survey.id,
"title": "State",
"question_type": "model",
"question_model_id": 81,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does ID 81 correspond to? I think you should use the _get function instead of hardcoding the ID here,
like the default value self.env["ir.model"]._get_id("model.name").

<div
class="col-sm-12 o_survey_choice_btn py-1 px-3 w-100 h-100 rounded mb-3"
>
<span t-out="answer_lines[0].value_model.display_name or None" />
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this error when trying to print the survey.
Image

Image Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already fix, now it manages if it has no answer.

Comment on lines +17 to +19
setTimeout(() => this._initAllInputs(), 100);
setTimeout(() => this._initAllInputs(), 500);
setTimeout(() => this._initAllInputs(), 1000);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why we do the same thing with different intervals. Could you add a better comment or docstring?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really need it, it is done in this._setupObserver(); ,we need init the selection. becuse when DOM is display first time it is not load. I don't know if there is a more practical way of implementing it.

errorMsg.style.fontSize = "0.875rem";
errorMsg.style.marginTop = "0.25rem";
errorMsg.style.display = "none";
errorMsg.textContent = "Please select a valid option from the list";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this text can be translated.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it can be translated

@eduezerouali-tecnativa eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch 3 times, most recently from bc6ae2e to 6b79df2 Compare March 20, 2026 16:58
@eduezerouali-tecnativa
Copy link
Copy Markdown
Author

@carlos-lopez-tecnativa thanks to take the time for review this PR. I did attend your comments. It is ready for review again. Thank you.

Comment on lines +20 to +31
if (!applySurveyPatch()) {
let attempts = 0;
const maxAttempts = 50;
const interval = setInterval(() => {
attempts++;
if (applySurveyPatch()) {
clearInterval(interval);
} else if (attempts >= maxAttempts) {
clearInterval(interval);
}
}, 100);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Could you add a docstring to explain the reason for this code? It is not clear to me.
I imagine the DOM is not ready yet, but what is the actual reason?

import publicWidget from "@web/legacy/js/public/public_widget";

publicWidget.registry.SurveyModelInput = publicWidget.Widget.extend({
selector: ".js_surveyform, .o_survey_form, body",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure if this code is loaded correctly. I attached a video where, if I start the survey from the test (or more specifically, if it displays the main page before starting the survey), it works fine. However, when I start the survey from a link from the Share wizard, it does not display the main page. The first question is loaded, but the input does not display the options. I suspect it is not loading correctly. Please take a look.

survey_question_type_model_selection.mp4

@carlos-lopez-tecnativa
Copy link
Copy Markdown

I see the code adds a feature to allow the user to select options, similar to a many2one field, which is nice, but what is the reason for implementing this here? Could an external library be used instead, such as Choices.js or Tom Select, etc?

@pedrobaeza
Copy link
Copy Markdown
Member

For such simple feature, it's better to not add such maintenance burden.

@eduezerouali-tecnativa eduezerouali-tecnativa force-pushed the 17.0-add-survey_question_type_model_selection branch from 6b79df2 to 6f30609 Compare April 22, 2026 09:05
@OCA-git-bot OCA-git-bot added mod:survey_question_type_model_selection Module survey_question_type_model_selection series:17.0 labels Apr 22, 2026
@eduezerouali-tecnativa
Copy link
Copy Markdown
Author

Add choices to it. Main changes apply:

  • Add choices lib.
  • survey_form.esm.js add choices + remove unnecessary code.
  • Templates match new select.
  • Tours adapted to select.

Changes do not affect following PR #210 #211
Also add @carlos-lopez-tecnativa as contributor as main reviewer.

please @pilarvargas-tecnativa @carlos-lopez-tecnativa could you review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:survey_question_type_model_selection Module survey_question_type_model_selection series:17.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants